package com.rc.saas.mini.service.tenant;

import com.rc.saas.mini.common.constant.WebConstant;
import com.rc.saas.mini.mapper.tenant.TenantAppInfoMapper;
import com.rc.saas.mini.model.tenant.TenantAppInfo;
import com.rc.saas.mini.model.tenant.TenantAppInfoExample;
import com.rc.saas.mini.service.tenant.TenantAppInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TenantAppInfoServiceImpl implements TenantAppInfoService {
    @Autowired
    private TenantAppInfoMapper tenantAppInfoMapper;

    @Override
    public TenantAppInfoMapper getMapper() {
        return tenantAppInfoMapper;
    }

    @Override
    public TenantAppInfo checkVersion(String appType, String tenantCode) {
        TenantAppInfoExample example = new TenantAppInfoExample();
        example.createCriteria().andAppTypeEqualTo(appType).andTenantCodeEqualTo(tenantCode);
        example.setOrderByClause("created_time desc");
        List<TenantAppInfo> list = tenantAppInfoMapper.selectByExample(example);
        if (list != null && list.size() > 0) {
            return list.get(0);
        } else {
            return null;
        }
    }

    @Override
    public TenantAppInfo selectAndroidDownload(String tenantCode) {
        TenantAppInfoExample example = new TenantAppInfoExample();
        example.createCriteria().andAppTypeEqualTo(WebConstant.CON1).andTenantCodeEqualTo(tenantCode);
        example.setOrderByClause("created_time desc");
        List<TenantAppInfo> list = tenantAppInfoMapper.selectByExample(example);
        if (list != null && list.size() > 0) {
            return list.get(0);
        } else {
            return null;
        }
    }

    @Override
    public TenantAppInfo selectIosDownload(String tenantCode) {
        TenantAppInfoExample example = new TenantAppInfoExample();
        example.createCriteria().andAppTypeEqualTo(WebConstant.CON0).andTenantCodeEqualTo(tenantCode);
        example.setOrderByClause("created_time desc");
        List<TenantAppInfo> list = tenantAppInfoMapper.selectByExample(example);
        if (list != null && list.size() > 0) {
            return list.get(0);
        } else {
            return null;
        }
    }
}
